import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-09
 * Time: 18:14
 */
public class triangle_Number {
    public static int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int sum = 0;
        for (int i = nums.length - 1; i >= 2; i--) {
            int left = 0;
            int right = i - 1;
            while (left < right) {
                if (nums[left] + nums[right] > nums[i]) {
                    sum += right-left;
                    right--;
                } else {
                    left++;
                }
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{2,2,3,4};
        System.out.println(triangleNumber(arr));
    }
}
